<!--
 * @Description: 个体信息管理
-->
<template>
  <BaseMainSlot>
    <template v-slot:zhactbar>
      <ActionBar
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :cancel-active="cancelActive"
        :save-active="saveActive"
        :has-save="false"
        :has-del="false"
        @add="add"
        @cancel="cancel"
        @edit="edit"
        @del="del"
        @save="save"
      />
    </template>
    <template v-slot:searchbox>
      <div class="label-input mr-20">
        <div class="label">个体名称:</div>
        <div class="input">
          <el-select
            v-model="condition.bionId"
            clearable
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in bionIdList"
              :key="index + 'bionId'"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </div>
      </div>
      <div class="label-input mr-20">
        <div class="label">耳标:</div>
        <div class="input">
          <el-input
            v-model="condition.eagTag"
            clearable
            placeholder="请输入耳标"
          />
        </div>
      </div>
      <div class="label-input mr-20">
        <div class="label">养殖时间段:</div>
        <div class="input">
          <el-date-picker
            v-model="condition.startDate"
            align="right"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始时间"
          />
          <el-date-picker
            v-model="condition.endDate"
            align="right"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束时间"
          />
        </div>
      </div>
      <!-- <div class="label-input mr-20">
        <div class="input"></div>
      </div> -->
      <div class="search ml-20" @click="queryInfoCondition">
        <img src="~@/assets/action-bar-icon/search.png" />
      </div>
    </template>
    <template v-slot:content>
      <el-table
        ref="tableDataRef"
        row-class-name="tablebox"
        highlight-current-row
        :data="tableData"
        stripe
        border
        max-height="88%"
        style="width: 100%"
        @selection-change="handleSelect"
        @current-change="updateInfo"
      >
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column type="index" label="序号" width="55" />
        <el-table-column prop="plantVarietyName" label="种养品种" width="130" />
        <el-table-column prop="eagTag" label="耳标" min-width="230" />

        <el-table-column prop="type" label="个体类型" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.type === "COMMON" ? "普通" : "繁育" }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="name" label="个体名称" width="150" />
        <el-table-column prop="facilityFullName" label="个体所在设施" min-width="190" />
        <el-table-column prop="gender" label="性别" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.gender === "FEMALE" ? "母羊" : "公羊" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="birthday" label="年龄" min-width="80">
          <template v-if="scope.row.plantVarietyName" slot-scope="scope">
            <span v-if="scope.row.birthday">
              {{ scope.row.birthday }}
            </span>
            <span v-else>—</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="weight"
          label="体重"
          width="150"
        ><template v-if="scope.row.plantVarietyName" slot-scope="scope">
          <span
            :class="scope.row.weight ? 'color' : ''"
            @click.stop="checkWeight(scope.row)"
          >
            {{ scope.row.weight ? scope.row.weight + '斤': "—" }}
          </span>
        </template></el-table-column>
        <el-table-column prop="clothingHairName" label="皮毛等级" width="80" />
        <el-table-column label="个体来源信息" width="150">
          <template slot-scope="scope">
            <span
              class="check"
              @click.stop="checkSource(scope.row)"
            >查看个体信息来源</span>
            <!-- <span>{{
              scope.row.source === "BREED" ? "内部繁殖" : "外部购买"
            }}</span> -->
          </template>
        </el-table-column>

        <!-- <el-table-column label="生长周期">
          <template slot-scope="scope">
            <span>{{ scope.row.startTime }}~{{ scope.row.endTime }}</span>
          </template>
        </el-table-column> -->
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="length"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
      <!-- 产看体重 -->
      <el-dialog title="历史称重信息" :visible.sync="weightDialog">
        <el-table :data="showWeight" stripe class="model-table">
          <el-table-column property="weight" label="体重">
            <template slot-scope="scope">
              {{ scope.row.weight }}斤
            </template>
          </el-table-column>
          <el-table-column property="recordTime" label="称重时间" />
        </el-table>
      </el-dialog>
      <!-- 查看个体信息来源 -->
      <el-dialog class="guanxi-dia" title="个体信息来源" :visible.sync="sorceDialog">
        <div class="guanxi-view">
          <div class="guanxi-left">
            <yangyang :bion-id="nowbionid" @setingyang="setingyang" />
          </div>
          <div class="guanxi-right">
            <div class="guanxi-title">{{ nowselectbiontypename }}信息</div>
            <div class="guanxi-line">
              <div class="line-name">个体名称</div>
              <div class="line-value">{{ nowselectmes.name }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">养殖品种</div>
              <div class="line-value">{{ nowselectmes.plantVarietyName }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">耳标</div>
              <div class="line-value font15">{{ nowselectmes.eagTag }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">性别</div>
              <div class="line-value">{{ nowselectmes.gender === "FEMALE" ? "母羊" : "公羊" }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">皮毛等级</div>
              <div class="line-value">{{ nowselectmes.clothingHair === "A" ?'甲':nowselectmes.clothingHair === "B" ?'乙':'丙' }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">代次</div>
              <div v-if="nowselectmes.generation > 0" class="line-value">
                {{ generationList[nowselectmes.generation -1].name }}
              </div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">年龄</div>
              <div class="line-value">{{ nowselectmes.age }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">出生日期</div>
              <div class="line-value">{{ nowselectmes.birthday }}</div>
            </div>
            <div class="guanxi-line ">
              <div class="line-name">入栏日期</div>
              <div class="line-value">{{ nowselectmes.startTime }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">个体来源</div>
              <div class="line-value">{{ nowselectmes.source === "BREED" ? "内部繁殖" : "外部购买" }}</div>
            </div>
            <div class="guanxi-line">
              <div class="line-name">所在位置</div>
              <div class="line-value-1">{{ nowselectmes.facilityFullName }}</div>
            </div>
          </div>
        </div>
      </el-dialog>
      <!-- 添加信息 -->
      <el-dialog title="添加生物个体信息管理" :visible.sync="addDialog">
        <el-form
          ref="addInfo"
          :model="addbio"
          label-position="left"
          label-width="50px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="养殖品种:"
                prop="plantVarietyId"
                :rules="[
                  {
                    required: true,
                    message: '请选择养殖品种',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.plantVarietyId"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in CultivatedVarieties"
                    :key="index + 'add'"
                    :label="item.plantVarietyName"
                    :value="item.plantVarietyId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="关联批次:"
                prop="batchNo"
                :rules="[
                  {
                    required: true,
                    message: '请选择关联批次',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.batchNo"
                  clearable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="(item, index) in batchList"
                    :key="index + 'batch'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="耳标:" prop="eagTag" :rules="rule.id">
                <el-input v-model="addbio.eagTag" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体类型:"
                prop="type"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体类型',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select v-model="addbio.type" placeholder="请选择" clearable>
                  <el-option
                    v-for="(item, index) in typeList"
                    :key="index + 'com'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="个体名称:"
                prop="name"
                :rules="[
                  {
                    required: true,
                    message: '请填写个体名称',
                    trigger:'blur',
                  },
                ]"
              >
                <el-input v-model="addbio.name" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体所在羊舍:"
                prop="facilityGroupId"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体所在羊舍',
                    trigger: ['blur', 'change'],
                  },
                ]"
              >
                <el-select
                  v-model="addbio.facilityGroupId"
                  placeholder="请选择"
                  clearable
                  @change="changeFacility(addbio.facilityGroupId)"
                >
                  <el-option
                    v-for="(item, index) in facilityList"
                    :key="index + 'Grou'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="性别:"
                prop="gender"
                :rules="[
                  {
                    required: true,
                    message: '请选择性别',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.gender"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="公" value="MALE" />
                  <el-option label="母" value="FEMALE" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体所在羊圈:"
                prop="facilityId"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体所在羊圈',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.facilityId"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in facility"
                    :key="item.facilityId"
                    :label="item.facilityName"
                    :value="item.facilityId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="皮毛等级:"
                prop="clothingHair"
                :rules="[
                  {
                    required: true,
                    message: '请选择皮毛等级',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.clothingHair"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in clothingHairList"
                    :key="index + 'clo'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体代次:"
                prop="generation"
                :rules="[
                  {
                    required: true,
                    message: '请选择代次',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.generation"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in generationList"
                    :key="index + 'generation'"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 个体来源 -->
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="个体来源:"
                prop="source"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体来源',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="addbio.source"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in sourceList"
                    :key="index + 'source'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 外部引入 -->
          <el-row v-if="addbio.source === 'PURCHASE'">
            <el-col :span="12">
              <el-form-item
                label="出生日期:"
                prop="birthday"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体出生日期',
                    trigger: 'change',
                  },
                ]"
              >
                <el-date-picker
                  v-model="addbio.birthday"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptionscreate"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="入栏日期:"
                prop="startTime"
                :rules="
                  {
                    required: true,
                    message: '请选择入栏日期',
                    trigger: 'change'
                  }
                "
              >
                <el-date-picker
                  v-model="addbio.startTime"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptions"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 内部繁殖 -->
          <el-row v-if="addbio.source === 'BREED'">
            <el-col :span="12">
              <el-form-item label="母本信息:">
                <el-select
                  v-model="addbio.matrix"
                  placeholder="请选择母本信息"
                  clearable
                  filterable
                  @change="birthTime(addbio.eweInfo)"
                >
                  <el-option
                    v-for="(item, index) in eweName"
                    :key="index"
                    :value="item.id"
                    :label="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="birthDate.length > 0" :span="12">
              <el-form-item label="出生日期:">
                <el-select
                  v-model="addbio.birthday"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in birthDate"
                    :key="index"
                    :value="item"
                    :label="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="birthDate.length === 0" :span="12">
              <el-form-item
                label="出生日期:"
                prop="birthday"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体出生日期',
                    trigger: 'change',
                  },
                ]"
              >
                <el-date-picker
                  v-model="addbio.birthday"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptionscreate"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="addbio.source === 'BREED'">
            <el-col :span="12">
              <el-form-item label="父本信息:">
                <el-select
                  v-model="addbio.father"
                  placeholder="请选择父本信息"
                  filterable
                  clearable
                >
                  <el-option
                    v-for="(item, index) in fatheryangList"
                    :key="index"
                    :value="item.id"
                    :label="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="入栏日期:"
                prop="startTime"
                :rules="
                  {
                    required: true,
                    message: '请选择入栏日期',
                    trigger: 'change'
                  }
                "
              >
                <el-date-picker
                  v-model="addbio.startTime"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptions"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="model-cancel-btn" @click="addDialog = false">取 消</el-button>
          <el-button type="primary" class="model-submit-btn" @click="confirmAddUser">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 添加成功后提示信息 -->
      <el-dialog title="添加成功" :visible.sync="addlastDialog" class="addtip">
        <div>是否继续添加下一条个体信息?</div>
        <div slot="footer" class="dialog-footer">
          <el-button class="model-cancel-btn" @click="addlastconcel()">否</el-button>
          <el-button type="primary" class="model-submit-btn" @click="addlastDialog = false">是</el-button>
        </div>
      </el-dialog>
      <!-- 修改信息 -->
      <el-dialog title="修改生物个体信息管理" :visible.sync="updatedialog">
        <el-form
          ref="updateInfo"
          :model="bio"
          label-position="left"
          label-width="50px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="养殖品种:"
                prop="plantVarietyId"
                :rules="[
                  {
                    required: true,
                    message: '请选择养殖品种',
                    trigger: 'change'
                  },
                ]"
              >
                <el-select
                  v-model="bio.plantVarietyId"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in CultivatedVarieties"
                    :key="index + 'update'"
                    :label="item.plantVarietyName"
                    :value="item.plantVarietyId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="关联批次:"
                prop="batchNo"
                :rules="[
                  {
                    required: true,
                    message: '请选择关联批次',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select v-model="bio.batchNo" clearable placeholder="请选择">
                  <el-option
                    v-for="(item, index) in batchList"
                    :key="index + 'batch'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="耳标:"
                prop="eagTag"
                :rules="rule.upId"
              ><!--  -->
                <el-input v-model="bio.eagTag" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体类型:"
                prop="type"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体类型',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select v-model="bio.type" placeholder="请选择" clearable>
                  <el-option
                    v-for="(item, index) in typeList"
                    :key="index + 'com'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="个体名称:"
                prop="name"
                :rules="[
                  {
                    required: true,
                    message: '请填写个体名称',
                    trigger: 'blur',
                  },
                ]"
              >
                <el-input v-model="bio.name" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体所在羊舍:"
                prop="facilityGroupId"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体所在羊舍',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="bio.facilityGroupId"
                  placeholder="请选择"
                  clearable
                  @change="changeFacility(bio.facilityGroupId)"
                >
                  <el-option
                    v-for="(item, index) in facilityList"
                    :key="index + 'Grou'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="性别:"
                prop="gender"
                :rules="[
                  {
                    required: true,
                    message: '请选择性别',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select v-model="bio.gender" placeholder="请选择" clearable>
                  <el-option label="公" value="MALE" />
                  <el-option label="母" value="FEMALE" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体所在羊圈:"
                prop="facilityId"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体所在羊圈',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="bio.facilityName"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in facility"
                    :key="item.facilityId"
                    :label="item.facilityName"
                    :value="item.facilityId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="皮毛等级:"
                prop="clothingHair"
                :rules="[
                  {
                    required: true,
                    message: '请选择皮毛等级',
                    trigger: 'change'
                  },
                ]"
              >
                <el-select
                  v-model="bio.clothingHair"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in clothingHairList"
                    :key="index + 'clo'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体代次:"
                prop="generation"
                :rules="[
                  {
                    required: true,
                    message: '请选择代次',
                    trigger: 'change',
                  },
                ]"
              >
                <el-select
                  v-model="bio.generation"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in generationList"
                    :key="index + 'generation'"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="入栏日期:"
                prop="startTime"
                :rules="[
                  {
                    required: true,
                    message: '请选择入栏日期',
                    trigger: 'change',
                  },
                ]"
              >
                <el-date-picker
                  v-model="bio.startTime"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptions1"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="个体来源:"
                prop="source"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体来源',
                    trigger: 'change'
                  },
                ]"
              >
                <el-select v-model="bio.source" placeholder="请选择" clearable>
                  <el-option
                    v-for="(item, index) in sourceList"
                    :key="index + 'source'"
                    :label="item.name"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col v-if="bio.source === 'BREED'" :span="12">
              <el-form-item label="母本信息:">
                <el-select
                  v-model="bio.matrix"
                  placeholder="请选择"
                  clearable
                  @change="birthTime(bio.eweInfo)"
                >
                  <el-option
                    v-for="(item, index) in eweName"
                    :key="index"
                    :value="item.id"
                    :label="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="birthDate.length > 0" :span="12">
              <el-form-item label="出生日期:">
                <el-select
                  v-model="bio.birthday"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in birthDate"
                    :key="index"
                    :value="item"
                    :label="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="birthDate.length === 0" :span="12">
              <el-form-item
                label="出生日期:"
                prop="birthday"
                :rules="[
                  {
                    required: true,
                    message: '请选择个体出生日期',
                    trigger: 'change',
                  },
                ]"
              >
                <el-date-picker
                  v-model="bio.birthday"
                  value-format="yyyy-MM-dd"
                  :picker-options="pickerOptionscreate"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="bio.source === 'BREED'">
            <el-col :span="12">
              <el-form-item label="父本信息:">
                <el-select
                  v-model="bio.father"
                  placeholder="请选择父本信息"
                  filterable
                  clearable
                >
                  <el-option
                    v-for="(item, index) in fatheryangList"
                    :key="index"
                    :value="item.id"
                    :label="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="model-cancel-btn" @click="updatedialog = false">取 消</el-button>
          <el-button type="primary" class="model-submit-btn" @click="updateUser">确 定</el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script>
import yangyang from "./components/yangguanxitu.vue"
import Pagination from "@/components/Pagination";
import ActionBar from "@/components/ActionBar/index";
import BaseMainSlot from "@/components/BaseMainSlot/baseone.vue";
import req from "@/api/digital-production/Individual-bio-management/information-management/index";
// import reqlx from "@/api/digital-production/breeding-management/individual-breeding-management/index";
import { mymixin } from "@/utils/mixin";
export default {
  name: "InformationManagement",
  components: {
    yangyang,
    Pagination,
    ActionBar,
    BaseMainSlot
  },
  mixins: [mymixin],
  data() {
    var that = this;
    var validateSid = (rule, value, callback) => {
      if (this.addbio.eagTag) {
        if (
          this.addbio.eagTag.length === 15 &&
        typeof Number(this.addbio.eagTag) === "number"
        ) {
          let count = this.pp(this.addbio.eagTag);
          count.then((res) => {
            if (res) {
              return callback(new Error("耳标已使用"));
            } else {
              callback();
            }
          });
        }
      }
    };
    var updateValidateSid = (rule, value, callback) => {
      if (
        this.originalEagTag !== this.bio.eagTag &&
        this.bio.eagTag.length === 15 &&
        typeof Number(this.bio.eagTag) === "number"
      ) {
        let count = this.pp(this.bio.eagTag);
        count.then((res) => {
          if (res) {
            return callback(new Error("耳标已使用"));
          } else {
            callback();
          }
        });
      } else if (this.originalEagTag === this.bio.eagTag) {
        callback();
      }
    };
    return {
      // ---代次generation---
      generationList: [
        { name: "一代", id: 1 },
        { name: "二代", id: 2 },
        { name: "三代", id: 3 },
        { name: "四代", id: 4 },
        { name: "五代", id: 5 },
        { name: "六代", id: 6 },
        { name: "七代", id: 7 }
      ],
      // 历史称重信息
      showWeight: [],
      originalEagTag: "",
      // ---
      rule: {
        id: [
          {
            required: true,
            message: "请填写耳标",
            trigger: ["change"]
          },
          {
            pattern: /^\d{15}$/,
            message: "请输入15位数字",
            trigger: ["change"]
          },
          {
            validator: validateSid,
            // message: "该耳标不可用",
            trigger: "change"
          }
        ],
        upId: [
          {
            required: true,
            message: "请填写耳标",
            trigger: ["blur", "change"]
          },
          {
            pattern: /^\d{15}$/,
            message: "请输入15位数字",
            trigger: ["blur", "change"]
          },
          {
            validator: updateValidateSid,
            // message: "该耳标不可用",
            trigger: "change"
          }
        ]
      },
      pickerOptions: {
        disabledDate(time) {
          // 开始时间的禁用
          // console.log(time)
          // if (new Date(time).getTime() >= new Date(that.addbio.birthday).getTime() - 86400000) {
          //   return false
          // } else {
          //   return true
          // }
          return new Date(time).getTime() < new Date(that.addbio.birthday).getTime() - 86400000;
        }
      },
      pickerOptionscreate: {
        disabledDate(time) {
          // 开始时间的禁用
          // return (
          //   new Date(time).getTime() > new Date(new Date(that.addbio.endTime).getTime()) &&
          //   new Date(time).getTime() < new Date(new Date(that.addbio.cultivationDate).getTime())
          // );
          return new Date(time).getTime() > new Date().getTime()
        }
      },
      // 结束时间
      pickerOptionsend: {
        disabledDate(time) {
          // 结束时间的禁用
          return new Date(time).getTime() < new Date(that.addbio.birthday).getTime();
        }
      },
      pickerOptions1: {
        disabledDate(time) {
          // 开始时间的禁用
          return new Date(time).getTime() < new Date(that.bio.birthday).getTime() - 86400000;
        }
      },
      pickerOptionscreate1: {
        disabledDate(time) {
          // 开始时间的禁用
          // return (
          //   new Date(time).getTime() > new Date(new Date(that.bio.endTime).getTime()) &&
          //    new Date(time).getTime() < new Date(new Date(that.bio.cultivationDate).getTime()
          //    ));
          // return new Date(time).getTime() < new Date(that.bio.cultivationDate).getTime()
          return new Date(time).getTime() < new Date().getTime()
        }
      },
      pickerOptionsend1: {
        disabledDate(time) {
          // 结束时间的禁用
          return new Date(time).getTime() < new Date(new Date(that.bio.birthday).getTime());
        }
      },
      bionIdList: [],
      NameList: [],
      IDList: [],
      queryName: "",
      queryId: "",
      typeList: [
        { name: "普通", value: "COMMON" },
        { name: "繁育", value: "BREED" }
      ],
      growthCycle: [
        { name: "幼年期", value: "INFANCY" },
        { name: "成熟期", value: "ADULT" },
        { name: "妊娠期", value: "ENCYESIS" },
        { name: "老年期", value: "GERONTIC" }
      ],
      sourceList: [
        { name: "内部繁殖", value: "BREED" },
        { name: "外部购买", value: "PURCHASE" }
      ],
      clothingHairList: [
        // { name: "棉毛型", value: "LINTER" },
        // { name: "沙毛型", value: "ROAN" },
        // { name: "中间型", value: "MIDDLE" }
        { name: "甲", value: "A" },
        { name: "乙", value: "B" },
        { name: "丙", value: "C" }
      ],
      // 设施组
      facilityList: [],
      // 羊圈
      facility: [],
      batchList: [],
      length: 0,
      addDialog: false,
      addlastDialog: false,
      updatedialog: false,
      weightDialog: false,
      // 条件查询
      condition: {
        startDate: "",
        endDate: "",
        name: "",
        number: ""
      },

      tableData: [],
      formTable: {},
      bio: {},
      addbio: {},
      eweName: [],
      eweid: 1,
      birthDate: [],
      eweBirth: [],
      CultivatedVarieties: [],
      // 父本可选择信息
      fatheryangList: [],
      startTime: "",
      endTime: "",
      // 新的个体关系
      // 当前关系图选中的羊id,
      nowselectbionid: "",
      nowselectmes: {},
      // 当前关系图中主体羊id
      nowbionid: "",
      sorceDialog: false,
      nowselectbiontypename: ""
    };
  },
  watch: {
    nowChanceStau(newval) {
      if (newval === "add") {
        this.adduser();
      } else if (newval === "edit") {
        this.updatedialog = true;
      }
    },
    tableData() {
      this.nowChanceStau = "";
    },
    addDialog(newval, oldval) {
      this.nowChanceStau = "";
      if (!newval) {
        this.$refs.addInfo.resetFields();
      }
    },
    updatedialog(newval, oldval) {
      this.nowChanceStau = "";
      if (!newval) {
        this.$refs.updateInfo.resetFields();
      }
    }
  },
  created() {
    this.pagingQuery();
    this.getEweInfo();
    this.getfatherList();
    this.getData();
    this.queryBionAll();
    this.HuSheep();
  },
  methods: {
    // 获取父本信息2022-04-26
    getfatherList() {
      let params = {
        gender: "MALE"
      }
      req.newsearchyang(params).then(
        (res) => {
          if (res.code === 1) {
            let Name = res.data || [];
            let listone = []
            if (Name[0]) {
              Name.forEach((item, index) => {
                listone.push({ name: item.name, id: item.bionId });
                if (Name.length - 1 === index) {
                  this.fatheryangList = listone
                }
              });
            }
          }
        }
      )
    },
    // 查看个体来源
    checkSource(val) {
      if (val.bionId) {
        this.nowselectbionid = ""
        this.nowselectmes = {}
        this.nowselectbiontypename = ""
        this.nowbionid = val.bionId;
        this.sorceDialog = true;
      } else {
        this.$message.error("没有标识！！")
      }
    },
    // 设置当前选中羊的id--第一次默认主体羊
    setingyang(e) {
      if (e.bionId) {
        // 查询当前选中羊的详细信息
        // let yangmes
        this.nowselectbionid = e.bionId
        if (e.guanxi) {
          if (e.guanxi === "bion") {
            this.nowselectbiontypename = "本体"
          }
          if (e.guanxi === "father") {
            this.nowselectbiontypename = "父亲"
          }
          if (e.guanxi === "mother") {
            this.nowselectbiontypename = "母亲"
          }
          if (e.guanxi === "grandma") {
            this.nowselectbiontypename = "祖母"
          }
          if (e.guanxi === "grandpa") {
            this.nowselectbiontypename = "祖父"
          }
          if (e.guanxi === "grandfather") {
            this.nowselectbiontypename = "外祖父"
          }
          if (e.guanxi === "grandmother") {
            this.nowselectbiontypename = "外祖母"
          }
        } else {
          this.nowselectbiontypename = "其他个体"
        }
        req.postQueryID(e.bionId).then(
          res => {
            if (res.code === 1) {
              let mes = res.data
              if (mes) {
                this.nowselectmes = mes
              }
            } else {
              this.$message.error("获取个体详细信息失败！！")
            }
          }
        )
      } else {
        this.$message.warning("缺少标识")
      }
    },
    // 查询体重
    checkWeight(val) {
      this.showWeight = [];
      if (val.bionId) {
        req.queryBionGrowthRecord(val.bionId).then((res) => {
          if (res.code === 1) {
            this.showWeight = res.data;
            this.weightDialog = true;
          }
        });
      }
    },
    // 查询耳标
    async pp(val) {
      let count = 0;
      return await req
        .queryBionByEagTag({
          breed: "HuSheep",
          eagTag: val
        })
        .then((res) => {
          if (res.code === 1) {
            let result = res.data || {};
            if (result.eagTag) {
              count++;
              return count;
            } else {
              // alert("该耳标可用！！！");
            }
          }
        });
      // return count;
    },
    queryBionAll() {
      req
        .queryBionAll({
          breed: "HuSheep"
        })
        .then((res) => {
          if (res.code === 1) {
            this.bionIdList = res.data || [];
          }
        });
    },
    // 根据条件查询
    queryInfoCondition() {
      req
        .postPageBio({
          page: this.currentPage,
          size: this.pageSize,
          entity: {
            breed: "HuSheep",
            eagTag: this.condition.eagTag,
            name: this.condition.bionId,
            startDate: this.condition.startDate,
            endDate: this.condition.endDate
          }
        })
        .then((res) => {
          if (res.code === 1) {
            res = res.data || {};
            this.length = res.totalElements;
            res = res.content || [];
            this.tableData = res;
            this.tableData = JSON.parse(JSON.stringify(res));
            this.clothingHairList.forEach((ITEM) => {
              this.tableData.forEach((item) => {
                if (ITEM.value === item.clothingHair) {
                  item.clothingHairName = ITEM.name;
                }
              });
            });
          }
        });
      this.queryId = "";
      this.queryName = "";
    },

    // 获取品种下拉列表
    HuSheep() {
      this.CultivatedVarieties = [];
      let arr = [];
      let farmingTypeNo = localStorage.getItem("farmingTypeNo")
      req.getQueryBreed(farmingTypeNo).then((res) => {
        let result = [];
        if (res.code === 1) {
          result = res.data || [];
          result.forEach((item) => {
            arr.push(item);
          });
        }
        this.CultivatedVarieties = arr;
        console.log('种养品种', this.CultivatedVarieties)
      });
    },
    // 获取批次数据,设施组下拉数据
    getData() {
      req.getBatchQueryByCondition().then((res) => {
        let arr = [];
        if (res.code === 1) {
          let result = res.data || [];
          result.forEach((item) => {
            arr.push({ value: item.batchNo, name: item.batchName });
          });
        }
        this.batchList = arr;
      });
      req.queryFacilityGroupAll({}).then((res) => {
        let arr1 = [];
        if (res.code === 1) {
          let result = res.data || [];
          result.forEach((item) => {
            arr1.push({ value: item.facilityGroupId, name: item.groupName });
          });
        }
        this.facilityList = arr1;
      });
    },
    // 查询羊舍
    changeFacility(val) {
      req
        .postFacilityQueryByCondition(val)
        .then((res) => {
          if (res.code === 1) {
            // let arr = [];
            let result = res.data || [];
            // console.log(result)
            this.facility = result;
            // console.log('我是facility')
            // result.forEach(item => {
            //   arr.push({ value: item.facilityId, name: item.facilityName })
            // })
            // this.facility = arr;
          }
        });
    },
    adduser() {
      this.formTable = {};
      this.bio = {};
      this.addbio = {}
      this.addDialog = true;
    },

    // 添加生物个体信息
    confirmAddUser() {
      this.$refs["addInfo"].validate((valid) => {
        if (valid) {
          let val = this.addbio;
          let params = {};
          if (val.source === "PURCHASE") {
            params = {
              organizationNo: Number(sessionStorage.getItem("organizationNo")),
              name: val.name,
              source: val.source,
              stage: "ADULT",
              gender: val.gender,
              startTime: val.startTime,
              type: val.type,
              status: "SURVIVAL",
              plantVarietyId: val.plantVarietyId,
              owner: true,
              batchNo: val.batchNo,
              facilityGroupId: val.facilityGroupId,
              facilityId: val.facilityId,
              birthday: val.birthday,
              generation: val.generation,
              eagTag: val.eagTag,
              clothingHair: val.clothingHair
            };
          } else if (val.source === "BREED") {
            params = {
              organizationNo: Number(sessionStorage.getItem("organizationNo")),
              name: val.name,
              source: val.source,
              stage: "ADULT",
              startTime: val.startTime,
              gender: val.gender,
              type: val.type,
              status: "SURVIVAL",
              plantVarietyId: val.plantVarietyId,
              owner: true,
              batchNo: val.batchNo,
              facilityId: val.facilityId,
              facilityGroupId: val.facilityGroupId,
              matrix: val.matrix, // 就多了这个
              father: val.father, // 和这个
              birthday: val.birthday,
              generation: val.generation,
              eagTag: val.eagTag,
              clothingHair: val.clothingHair
            };
          }
          req.postAdd(params).then((res) => {
            if (res && res.code === 1) {
              this.$message.success("添加成功");
              this.addlastDialog = true;
            } else {
              if (res.msg) {
                this.$message.error(res.msg);
              } else {
                this.$message.error("添加失败！！！");
              }
            }
          });
          // this.addDialog = false;
        } else {
          this.$message.error("请将信息填写完整！！！");
          return false;
        }
      });
    },
    // 是否继续添加相关
    addlastconcel() {
      this.addlastDialog = false;
      this.addDialog = false;
      this.pagingQuery();
    },
    // 修改
    updateUser() {
      // console.log(111)
      this.$refs["updateInfo"].validate((valid) => {
        console.log(valid)
        if (valid) {
          let val = this.bio;
          let params = {};
          if (val.source === "PURCHASE") {
            params = {
              organizationNo: sessionStorage.getItem("organizationNo"),
              bionId: val.bionId,
              gender: val.gender,
              name: val.name,
              number: val.name,
              source: val.source,
              stage: "ADULT",
              startTime: val.startTime,
              type: val.type,
              status: "SURVIVAL",
              plantVarietyId: val.plantVarietyId,
              owner: val.owner,
              batchNo: this.bio.batchNo,
              facilityId: val.facilityId,
              facilityGroupId: val.facilityGroupId,
              birthday: this.bio.birthday,
              generation: val.generation,
              eagTag: val.eagTag,
              clothingHair: val.clothingHair
            };
          } else if (val.source === "BREED") {
            params = {
              organizationNo: sessionStorage.getItem("organizationNo"),
              bionId: val.bionId,
              gender: val.gender,
              name: val.name,
              number: val.name,
              source: val.source,
              stage: "ADULT",
              birthday: val.birthday,
              generation: val.generation,
              startTime: val.startTime,
              type: val.type,
              status: "SURVIVAL",
              plantVarietyId: val.plantVarietyId,
              owner: val.owner,
              matrix: val.matrix,
              father: val.father,
              batchNo: this.bio.batchNo,
              facilityId: val.facilityId,
              clothingHair: val.clothingHair,
              eagTag: val.eagTag,
              facilityGroupId: val.facilityGroupId
            };
          }
          req.postEdit(params).then((res) => {
            if (res.code === 1) {
              this.$message.success("修改成功");
              this.updatedialog = false;
              this.pagingQuery();
            } else {
              this.$message.error("修改失败！！！");
            }
          });
        } else {
          this.$message.error("请将信息填写完整！！！");
          return false;
        }
      });
    },

    // 获取母羊信息
    getEweInfo() {
      req.getQueryEweInformation("HuSheep").then((res) => {
        if (res.code === 1) {
          let Name = [];
          Name = res.data || [];
          Name.forEach((item) => {
            this.eweName.push({ name: item.name, id: item.bionId });
          });
        }
      });
    },

    // 获取分页数据
    pagingQuery() {
      req
        .postPageBio({
          page: this.currentPage,
          size: this.pageSize,
          entity: {
            breed: "HuSheep"
          }
        })
        .then((res) => {
          if (res.code === 1) {
            this.cancel()
            res = res.data || {};
            this.length = res.totalElements;
            res = res.content || [];
            this.tableData = JSON.parse(JSON.stringify(res));
            this.clothingHairList.forEach((ITEM) => {
              this.tableData.forEach((item) => {
                if (ITEM.value === item.clothingHair) {
                  item.clothingHairName = ITEM.name;
                }
              });
            });
          }
        });
    },

    // 查询生育时间
    birthTime(val) {
      console.log(this.addbio)
      req
        .postQueryByCondition({
          bionId: val
        })
        .then((res) => {
          let arr = [];
          if (res.code === 1) {
            let bir = res.data || [];
            bir.forEach((item) => {
              arr.push(this.formatDateTime_(item.birthTime));
            });
          }
          this.birthDate = arr;
        });
    },

    // 获取当前行的数据
    updateInfo(val) {
      if (val) {
        req.postQueryID(val.bionId).then((res) => {
          let result = res.data || {};
          this.bio = result;
        });
        this.bio = val;
        this.CultivatedVarieties = [];
        if (val) {
          this.editActive = true;
          this.cancelActive = true;
          this.bio = {
            organizationNo: sessionStorage.getItem("organizationNo"),
            bionId: val.bionId,
            gender: val.gender,
            name: val.name,
            source: val.source,
            startTime: val.startTime,
            type: val.type,
            owner: val.owner,
            plantVarietyId: val.plantVarietyId,
            // cultivationDate: val.cultivationDate,
            clothingHair: val.clothingHair,
            eagTag: val.eagTag,
            facilityId: val.facilityId,
            facilityGroupId: val.facilityGroupId,
            matrix: val.matrix,
            birthday: val.birthday,
            batchNo: val.batchNo,
            generation: val.generation
          };
        } else {
          this.editActive = true;
        }
        this.bio = val;
        this.eweInfo = val.matrix;
        this.CultivatedVarieties = [
          {
            plantVarietyId: val.plantVarietyId,
            plantVarietyName: val.plantVarietyName
          }
        ];
        this.originalEagTag = val.eagTag;
      }

      this.nowChanceStau = "";
    },

    // 通过是否勾选数据来决定删除按钮是否具有删除功能
    handleSelect() {
      let list = this.$refs.tableDataRef.selection;
      this.selectlist = list;
      if (list.length > 0) {
        this.delActive = true;
      } else {
        this.delActive = false;
      }
      return list;
    },

    // 实际的删除功能，操作的是原始拿来的数据
    delmessage() {},
    // 分页功能实现
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.pagingQuery();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.pagingQuery();
    },
    cancel() {
      this.$refs.tableDataRef.setCurrentRow();
      this.$refs.tableDataRef.clearSelection();
      this.nowChanceStau = "";
      this.addActive = true;
      this.cancelActive = false;
      this.editActive = false;
    }
  }
};
/* </> */
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";
// 羊关系弹窗
.guanxi-dia{
  ::v-deep .el-dialog {
    width:1000px !important;
    height: 550px;
    max-height: 700px;
  }
}
.guanxi-view{
  width: 960px;
  margin-left: 20px;
  padding: 20px 0;
  display: flex;
  justify-content: space-around;
  .guanxi-left{
    width: 500px;
    // background: #006e91;
  }
  .guanxi-right{
    width: 400px;
    box-shadow:  0 1px 4px rgba(0, 21, 41, 0.08);;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    .guanxi-title{
      width: 400px;
      height: 40px;
      line-height: 40px;
      white-space: nowrap;
      text-align: center;
      background-color: #b7d0d8;
      font-size: 20px;
      font-weight: 600;
    }
    .guanxi-line{
      width: auto;
      // background: yellow;
      height: 30px;
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      // justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;
      .line-name{
        width: 60px;
        height: 30px;
        line-height: 30px;
        white-space: nowrap;
        text-align: center;
        // background-color: #006e91;
      }
      .line-value{
        width: 140px;
        height: 30px;
        line-height: 30px;
        background-color: #ebedef;
        text-align: center;
      }
      .line-value-1{
        width: 340px;
        height: 30px;
        line-height: 30px;
        background-color: #ebedef;
        text-align: center;
      }
      .font15{
        font-size: 12px;
      }
    }
  }
}
// ----
.addtip{
  ::v-deep .el-dialog{
    width: 350px !important;
  }
}
::v-deep .el-table {
  overflow: auto;
}
::v-deep .el-col {
  min-height: 1px;
  text-align: center;
}
::v-deep .el-dialog__body {
  // background: #0085a0;
  .el-input {
    width: 100%;
  }
  .el-select {
    //充满父元素（el-col）
    width: 100%;
  }
}
li {
  list-style: none;
  font-size: 18px;
  height: 40px;
  line-height: 40px;
}
.wrap {
  display: flex;
  justify-content: space-around;
  text-align: center;
  .father,
  .bio {
    width: 49%;
    .el-col {
      display: flex;
      justify-content: flex-start;
      line-height: 30px;
    }
    .el-input {
      height: 50px;
    }
  }
}
.detail {
  height: 32 px;
  display: flex;
  align-items: center;
}
.detailBox {
  display: inline-block;
  height: 20px;
}
.detailBox {
  width: 150px;
  // background: #a9a5bd63;
  line-height: 20px;
  white-space: nowrap;
  // text-overflow: ellipsis;
  overflow: hidden;
  //background: chartreuse;
  text-align: center;
}
.fontmin{
  font-size: 12px;
}
.color,
.check {
  cursor: pointer;
  color: #33bad4;
  border-bottom: 1px solid #33bad4;
}
// 弹框底下按钮样式
.model-submit-btn{
background-color: #006e91;
    border-color: #006e91;
    &:hover{
      background-color: #006f91b9;
    border-color: #006f91b9;
    }
}
.model-cancel-btn{
  &:hover{
      background-color: #006f9128;
    border-color: #006e91;
    color:#006e91
    }
}
// 弹框表格样式
  ::v-deep .model-table{
      // el-table__row{
        background-color: #003947;
        // }
}
</style>
